<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>测试</title>
  <script src="./05-Promise自定义封装-异常穿透与值传递.js"></script>
</head>
<body>
</body>
<script>
  let p = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('hello Promsie')
        // reject('hello error')
        // throw 'throw error'
      },2000);
        // resolve('hello Promsie')
        // reject('hello error')
        // throw 'throw error'
  })
  // let result = p.then(res => {
              // console.log(res);
                // return 'Hello World'
                // throw 'Hello error'
                // return new Promise((resolve,reject)=>{reject('hello reject')})
              // },err=>{
                // console.log(err); 
                // return 'Hello World'
                // throw 'Hello error'
                // return new Promise((resolve,reject)=>{reject('hello reject')})
              // });
  // console.log('result--',result);

  //异常穿透与值转递
  // 值传递
  // let result = p.catch(err=>{
  //     console.log(err);
  //     // return 'hello 值传递'
  //     throw 'Hello error'
  //   })
  // 异常穿透
   let result = p.then((res)=>{
                        console.log(res); 
                        return'first';})
                 .then((res)=>{
                        console.log(res); 
                        throw 'Hello errorssss';
                        return'second';})
                 .then((res)=>{
                        console.log(res); 
                        return 'third'})
                 .catch(err=>{
                        console.log('catch-----------');
                        console.log(err);
                        return 'catch hello world'
                  })
    console.log('result--',result);
</script>

</html>